﻿using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;


public partial class PropSet
{
    /// <summary>
    /// 转为字符串
    /// </summary>
    public override string ToString()
    {
        string str = string.Empty;

        for (int i = 1, iMax = (int)PropType.MAX; i < iMax; ++i)
        {
            if (!string.IsNullOrEmpty(str)) str += ",";
            str += i + ":" + this[i];
        }

        return str;
    }


    /// <summary>
    /// 转换字符串到属性
    /// </summary>
    public static PropSet AnalysisStr(string str)
    {
        string[] propInfos = str.Split(',');
        PropSet pSet = new PropSet();

        foreach(string propInfo in propInfos)
        {
            string[] strs = propInfo.Split(':');

            if (strs.Length < 2) continue;

            int key;
            float value;
            int.TryParse(strs[0], out key);
            float.TryParse(strs[1], out value);

            pSet[key] = value;
        }

        return pSet;
    }
}
